﻿/// <reference path="../../Scripts/jquery-1.4.1-vsdoc.js" />

//        $(function () {
//            altLevelTable("#tableCateList");
//        });

function addCate() {
	_bigCateId = 0;
	_popupWin(true);
}
function addSubCate(bigCateId, name) {
	_bigCateId = bigCateId;
	_popupWin(true, "为 " + name + " 添加子类别");
}
function editCate(cateId, name) {
	_editCateId = cateId;
	$("#txtCateName").val(name);
	_popupWin(false);
}
function deleteCate(cateId) {
	if (confirm("确认删除?")) {
		$.post("/Category/Delete", { "id": cateId }, _ajaxSuccessed);
	}
}
function submitData() {
	var name = $("#txtCateName").val();
	if (_isAdd) {
		_addCate(name);
	}
	else {
		_editCate(name);
	}
}
function toggleSubCate(id, text) {
	var e = $('#childCate_' + id);
	if (e.css("display") == "none") {
		text = "- " + text;
		e.show(200);
	}
	else {
		text = "+ " + text;
		e.hide(200);
	}
	$("#bigCateTitle_" + id).text(text);
}
//function closePopup() {
//	$("#divPopup").dialog("close");
//}

var _bigCateId = 0;
var _editCateId = 0;
var _isAdd = true;

function _popupWin(isAdd, title) {
	_isAdd = isAdd;

	if (title == undefined) {
		title = isAdd ? "添加类别" : "编辑类别";
	}

	$("#divPopup").dialog({
		show: "fold",
		hide: "fold",
		width: 300,
		height: 120,
		title: title,
		modal: true
	});
}
function _addCate(name) {
	if (_bigCateId != undefined && _bigCateId != 0) {
		$.post("/Category/AddSubCate", { "bigCateId": _bigCateId, "name": name }, _ajaxSuccessed);
	}
	else {
		$.post("/Category/AddCate", { "name": name }, _ajaxSuccessed);
	}
}
function _editCate(name) {
	$.post("/Category/EditCate", { "id": _editCateId, "name": name }, _ajaxSuccessed);
}
function _ajaxSuccessed(res) {
	if (res.Success) {
		document.location.reload(); // = document.location;
	}
	else {
		alert(res.Message);
	}
}